<!DOCTYPE html>
<script src='vendor/three.js/build/three.js'></script>
<script src='vendor/three.js/examples/js/loaders/STLLoader.js'></script>
<script src='vendor/three.js/examples/js/loaders/ColladaLoader.js'></script>
<script src='vendor/three.js/examples/js/loaders/OBJLoader.js'></script>
<script src='vendor/three.js/examples/js/loaders/MTLLoader.js'></script>
<script src='vendor/three.js/examples/js/loaders/OBJMTLLoader.js'></script>
<script src='vendor/three.js/examples/js/loaders/BinaryLoader.js'></script>
<script src='../threex.universalloader.js'></script>
<body style='margin: 0px; background-color: #bbbbbb; overflow: hidden;'><script>
	var renderer	= new THREE.WebGLRenderer({
		antialias	: true
	});
	renderer.setSize( window.innerWidth, window.innerHeight );
	document.body.appendChild( renderer.domElement );

	var onRenderFcts= [];
	var scene	= new THREE.Scene();
	var camera	= new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.01, 1000);
	camera.position.z = 1;

	//////////////////////////////////////////////////////////////////////////////////
	//		set 3 point lighting						//
	//////////////////////////////////////////////////////////////////////////////////

	;(function(){
		// add a ambient light
		var light	= new THREE.AmbientLight( 0x020202 )
		scene.add( light )
		// add a light in front
		var light	= new THREE.DirectionalLight('white', 1)
		light.position.set(0.5, 0.5, 2)
		scene.add( light )
		// add a light behind
		var light	= new THREE.DirectionalLight('white', 0.75)
		light.position.set(-0.5, -0.5, -2)
		scene.add( light )		
	})()

	

	//////////////////////////////////////////////////////////////////////////////////
	//		Comment								//
	//////////////////////////////////////////////////////////////////////////////////

	var urls	= []
	var urls	= 'models/stl/ascii/pr2_head_pan.stl'
	var urls	= 'models/collada/monster/monster.dae'
	// var urls	= 'models/Suzanne.js'
	// var urls	= 'obj/tree/tree.js'
	// var urls	= 'obj/tree/tree.obj'
	// var urls	= 'obj/female02/female02.obj'
	// var urls	= ['obj/female02/female02.mtl', 'obj/female02/female02.obj']
	// var urls	= ['obj/female02/female02.obj', 'obj/female02/female02.mtl']
	// var urls	= 'obj/female02/Female02_slim.js'

	var loader	= new THREEx.UniversalLoader()
	loader.load(urls, function(object3d){

		// normalize the scale
		var boundingBox	= new THREE.Box3().setFromObject(object3d)
		var size	= boundingBox.size()
		var scaleScalar	= Math.max(size.x, Math.max(size.y, size.z))
		object3d.scale.divideScalar(scaleScalar)

		// normalize the position
		var boundingBox	= new THREE.Box3().setFromObject(object3d)
		object3d.position.copy( boundingBox.center().negate() )


		// add the object to the scene
		scene.add(object3d)
	})

	//////////////////////////////////////////////////////////////////////////////////
	//		Camera Controls							//
	//////////////////////////////////////////////////////////////////////////////////
	var mouse	= {x : 0, y : 0}
	document.addEventListener('mousemove', function(event){
		mouse.x	= (event.clientX / window.innerWidth ) - 0.5
		mouse.y	= (event.clientY / window.innerHeight) - 0.5
	}, false)
	onRenderFcts.push(function(delta, now){
		camera.position.x += (mouse.x*5 - camera.position.x) * (delta*3)
		camera.position.y += (mouse.y*5 - camera.position.y) * (delta*3)
		camera.lookAt( scene.position )
	})



	//////////////////////////////////////////////////////////////////////////////////
	//		render the scene						//
	//////////////////////////////////////////////////////////////////////////////////
	onRenderFcts.push(function(){
		renderer.render( scene, camera );
	})
	

	//////////////////////////////////////////////////////////////////////////////////
	//		loop runner							//
	//////////////////////////////////////////////////////////////////////////////////
	var lastTimeMsec= null
	requestAnimationFrame(function animate(nowMsec){
		// keep looping
		requestAnimationFrame( animate );
		// measure time
		lastTimeMsec	= lastTimeMsec || nowMsec-1000/60
		var deltaMsec	= Math.min(200, nowMsec - lastTimeMsec)
		lastTimeMsec	= nowMsec
		// call each update function
		onRenderFcts.forEach(function(onRenderFct){
			onRenderFct(deltaMsec/1000, nowMsec/1000)
		})
	})
</script></body>
